package org.come.npc;

import org.come.Frame.XingPanSXJframe;
import org.come.Jpanel.FrameMessageChangeJpanel;
import org.come.action.NpcMenuAction;
import org.come.bean.PrivateData;
import org.come.bean.Skill;
import org.come.until.AnalysisString;
import org.come.until.CutButtonImage;
import org.come.until.SendRoleAndRolesummingUntil;
import org.come.until.UserMessUntil;

import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;

import javax.swing.*;

/**
 * 学习星盘
 * @author Administrator
 *
 */
public class SkillLearn3 implements NpcMenuAction{

    @Override
    public void menuControl(String type) {
        if (type==null|| "".equals(type)) {return;}
        Skill skill=UserMessUntil.getskill1(type);
        if (skill==null) {return;}
        PrivateData data=RoleData.getRoleData().getPrivateData();
        String[] vs=data.getSkill("X");
        if (vs!=null) {
            for (int i = 0; i < vs.length; i++) {
                if (vs[0].startsWith(skill.getSkillid())) {
                    FrameMessageChangeJpanel.addtext(5,"你已经学会了该技能",null,null);
                    return;
                }
            }
        }
        int id =Integer.parseInt(skill.getSkillid());
        int lvl=Integer.parseInt(skill.getSkilllevel());

        StringBuffer buffer=new StringBuffer();
        if (vs!=null) {
            for (int i = 0; i < vs.length; i++) {
                if (buffer.length()!=0) {buffer.append("#");}
                buffer.append(vs[i]);
            }
        }
        if (buffer.length()!=0) {buffer.append("#");}
        buffer.append(id);
        buffer.append("_");
        int sld = AnalysisString.shuliandu(ImageMixDeal.userimg.getRoleShow().getGrade());
        buffer.append(sld);
        data.setSkills("X",buffer.toString());
        SendRoleAndRolesummingUntil.sendRole(data);
        FrameMessageChangeJpanel.addtext(5,"你学会了"+skill.getSkillname(),null,null);
        ImageIcon imgSkill = CutButtonImage.getImage("inkImg/old/skill/fighting-skill/" + skill.getSkillid() + ".png", 50, 50);
        XingPanSXJframe.getXingPanSXJpanel().getLabskill().setIcon(imgSkill);
        XingPanSXJframe.getXingPanSXJpanel().getLabskill().setText(skill.getSkillname());
    }

}
